package domain.entities;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

import static javax.persistence.GenerationType.IDENTITY;

/**
 * Created with IntelliJ IDEA.
 * User: nico
 * Date: 22/08/12
 * Time: 10:32
 * To change this template use File | Settings | File Templates.
 */
@Entity
public class VendorType implements Comparable{

    private Integer id;
    private String descripcion;
    private List<Vendorcentral> vendorcentrales = new ArrayList<Vendorcentral>();

    public VendorType(Integer id,
                      String descripcion) {
        this.id = id;
        this.descripcion = descripcion;
    }

    public VendorType(String descripcion) {

        this.descripcion = descripcion;
    }

    public VendorType() {
    }


    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "id", unique = true, nullable = false)
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }
    @Column(name = "descripcion")
    public String getDescripcion() {
        return descripcion;
    }

    public void setDescripcion(String descripcion) {
        this.descripcion = descripcion;
    }

    @Override
    public int compareTo(Object o) {
        VendorType otro = (VendorType)o;
        return this.descripcion.compareTo(otro.descripcion);
    }

    @OneToMany(mappedBy = "type")
    @LazyCollection(LazyCollectionOption.FALSE)
    public List<Vendorcentral> getVendorcentrales() {
        return this.vendorcentrales;
    }

    public void setVendorcentrales(List<Vendorcentral> vendorcentrales) {
        this.vendorcentrales = vendorcentrales;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof VendorType)) return false;

        VendorType that = (VendorType) o;

        if (!id.equals(that.id)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return id.hashCode();
    }
}